package com.audaque.springboot.foshanupload.kafka.handler;

/**
 * @author zgb
 * @desc ...
 * @date 2023-04-14 15:09:25
 */

import org.apache.kafka.clients.consumer.Consumer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.kafka.listener.ConsumerAwareListenerErrorHandler;
import org.springframework.kafka.listener.ListenerExecutionFailedException;
import org.springframework.messaging.Message;

/**
 * 消费异常处理器
 */
@Configuration
public class MyConsumerAwareErrorHandler {

    @Bean
    public ConsumerAwareListenerErrorHandler consumerAwareListenerErrorHandler() {
        return new ConsumerAwareListenerErrorHandler() {
            @Override
            public Object handleError(Message<?> message, ListenerExecutionFailedException e, Consumer<?, ?> consumer) {
                // 编写消费者异常处理逻辑
                System.out.println("消费发生异常...");
                System.out.println("异常信息：" + e.getMessage());
                return null;
            }
        };
    }

}
